<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>工艺通知单管理</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<link rel="stylesheet" href="${pageContext.request.contextPath }/assets/css/layui.css"  media="all">
	<link rel="stylesheet" href="${pageContext.request.contextPath }/assets/css/toastr.min.css"  media="all">
</head>
<body>
<div class="demoTable" style="padding:10px 0 0 15px">
    <div class="layui-inline">
        <input class="layui-input" name="keyword" id="keyword" autocomplete="off" placeholder="请输入编号">
    </div>
    <button class="layui-btn layui-btn-blue" style="margin: 0 0 0 10px" data-type="reload"><i class="layui-icon layui-icon-search">  搜索</i></button>
</div>
<table class="layui-hide" id="test" lay-filter="test"></table>

<div id="formDiv2" hidden>
	<form class="layui-form" id="addform">
		<br>
		<h1 align="center">工艺变更通知单</h1><br>
		<div class="layui-form-item">
			<div class="layui-inline">
				<label class="layui-form-label" style="width: 100px;">编号</label>
				<div class="layui-input-inline">
					<input class="layui-input" lay-verify="noticeNum" type="text" id="noticeNum" name="noticeNum" style="width:300px;">
				</div><span style="color:red; font-size: 24px;float: right;margin: 10px -5em 0 0;">*</span>
			</div>
			<div class="layui-inline" style="padding-left: 5em;">
				<label class="layui-form-label" style="width: 100px;">日期</label>
				<div class="layui-input-inline">
					<input class="layui-input" lay-verify="noticeDate" type="text" id="noticeDate" name="noticeDate" style="width:300px;">
				</div><span style="color:red; font-size: 24px;float: right;margin: 10px -5em 0 0;">*</span>
			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-inline">
				<label class="layui-form-label" style="width: 100px;">有效期</label>
				<div class="layui-input-inline">
					<input class="layui-input" lay-verify="validityPeriod" type="text" id="validityPeriod" name="validityPeriod" style="width:300px;">
				</div><span style="color:red; font-size: 24px;float: right;margin: 10px -5em 0 0;">*</span>
			</div>
			<div class="layui-inline" style="padding-left: 5em;">
				<label class="layui-form-label" style="width: 100px;">适用工序</label>
				<div class="layui-input-inline" style="width: 300px;">
					<select class="layui-input" lay-search="" id="applicableProcess" name="applicableProcess" lay-verify="applicableProcess">
						<option value=""></option>
						<c:forEach items="${pList }" var="p">
							<option value="${p.pname }">${p.pname }</option>
						</c:forEach>
					</select>
				</div><span style="color:red; font-size: 24px;float: left;margin: 10px -5em 0 0;">*</span>
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label" style="width: 100px;">内容</label>
			<div class="layui-input-inline">
				<textarea class="layui-textarea" lay-verify="content" id="content" name="content" style="width:500px;"></textarea>
			</div><span style="color:red; font-size: 24px;float: left;margin: 40px 0 0 13em;">*</span>
		</div>
		<button id="subBtn1" class="layui-btn layui-btn-blue" lay-submit lay-filter="addform" style="margin-left:350px;margin-bottom: 1em;">提交</button>&emsp;&emsp;&emsp;&emsp;<button type="reset" style="margin-bottom: 1em;" class="layui-btn layui-btn-primary">重置</button>
	</form>
</div>

<script type="text/html" id="toolbarDemo">
	<div class="layui-btn-container">
		<button class="layui-btn layui-btn-blue" lay-event="add"><i class="layui-icon layui-icon-add-1">  新增</i></button>
	</div>
</script>
              
          
<script src="${pageContext.request.contextPath }/assets/layui.js" charset="utf-8"></script>
<script src="${pageContext.request.contextPath }/assets/layui.all.js"></script>
<script src="${pageContext.request.contextPath }/assets/js/jquery.min.js" charset="utf-8"></script>
<script src="${pageContext.request.contextPath }/assets/js/toastr.min.js" charset="utf-8"></script>
<jsp:include page="ScriptInc.jsp"></jsp:include>
 
<script>
layui.use(['table','layer','upload','form'], function(){
	var table = layui.table;
	var laydate = layui.laydate;
	
	var myDate = new Date();
	var mytime = myDate.toLocaleDateString();     //获取当前日期
	
	//执行一个laydate实例
	laydate.render({
		elem: '#noticeDate' //指定元素
		,min: mytime
	});
	
	laydate.render({
		elem: '#validityPeriod' //指定元素
		,min: mytime
	});
	
	var layer = layui.layer,
    form = layui.form;
	var $ = layui.jquery, active = {
			reload:function () {
				var keyword = $("#keyword").val();
				table.reload('contenttable',{
					method:'get',
					where:{noticeNum: keyword}
				});
			}
		}
	$('.layui-btn').on('click', function(){
        var type = $(this).data('type');
        active[type] ? active[type].call(this) : '';
    });
	table.render({
	    elem: '#test'
	    ,url:'${pageContext.request.contextPath }/changeNotice/listPageChangeNotice.do'
	    ,toolbar: '#toolbarDemo'
	    ,title: '工艺通知单数据表'
	    ,id :'contenttable'
	    ,limits:[10,20,30]
	    ,cols: [[
	      {type: 'checkbox', fixed: 'left'}
	      ,{type: 'numbers', title:'序号', fixed: 'left', width:'5%', unresize: true, sort: true}
	      ,{field:'noticeNum', title:'编号'}
	      ,{field:'draftDepartment', title:'制定部门'}
	      ,{field:'noticeDate', title:'制定日期', templet: function(d){
	          return timestampToDate(d.noticeDate.time);
	      }}
	      ,{field:'validityPeriod', title:'有效期'}
	      ,{field:'applicableProcess', title:'适用工序'}
	      ,{field:'content', title:'内容'}
	      ,{field:'draftPerson', title:'拟定人'}
	      ,{field:'reserve1', title:'处理结果', templet: function(d){
	          if (d.reserve1 == '0') {
				return '未处理';
			}
	          if (d.reserve1 == '1') {
	        	  return '处理中';
			}
	          if (d.reserve1 == '2') {
	        	  return '已通过';
			}
	          if (d.reserve1 == '3') {
	        	  return '已驳回';
			}
	      }}
	      ,{field:'approvalRecord', title:'处理记录', templet: function(d){
	    	  return "<a href='javascript:void(0)' style='color:#4D61B3' onclick='attachDeviceEvent(\""+
	    			  d.reserve5+"\",\""+d.reserve2+"\",\""+d.qSignature+"\",\""+d.reserve3+"\",\""+
	    			  d.tSignature+"\",\""+d.reserve4+"\",\""+d.maSignature+"\",\""+d.mOpinion+
	    			  "\",\""+d.mSignature+"\")'>"+'查看详细'+"</a>";
	      }}
	    ]]
	    ,page: true
	});
	
	//头工具栏事件
	table.on('toolbar(test)', function(obj){
		var checkStatus = table.checkStatus(obj.config.id);
	    switch(obj.event){
	    	case 'add':
	    		layer.open({
					  type: 1 		//Page层类型
					  ,area: ['60%', '50%'] //宽  高
					  ,title: '新增'
					  ,shade: 0.6 	//遮罩透明度
					  ,shadeClose: true //点击遮罩关闭
					  ,maxmin: true //允许全屏最小化
					  ,anim: 1 		//0-6的动画形式，-1不开启
					  ,content: $('#formDiv2')
					  ,success: function () {
						  document.getElementById("addform").reset();
					  }
					  ,end: function () {
						  var formDiv = document.getElementById('formDiv2');
						  formDiv.style.display = '';
					  }
					});
	      	break;
	      	case 'select':
	      		console.log(obj)
	      	break;
	    };
	});
	
	/**
     * 表单校验
     */
    form.verify({
    	//value：表单的值、item：表单的DOM对象
    	noticeNum: function(value){
    		if(value == ''){
    			return '编号不能为空';
    		}
    	},
    	noticeDate: function(value){
    		if(value == ''){
    			return '日期不能为空';
    		}
    	},
    	validityPeriod: function(value){
    		if(value == ''){
    			return '有效期不能为空';
    		}
    	},
    	applicableProcess: function(value){
    		if(value == ''){
    			return '适用工序不能为空';
    		}
    	},
    	content: function(value){
    		if(value == ''){
    			return '内容不能为空';
    		}
    	}
    });
	
    /**
     * 通用表单提交(AJAX方式)（新增）
     */
    form.on('submit(addform)', function (data) {
    	$("#subBtn1").attr("disabled",true);
    	$.ajax({
			url : '${pageContext.request.contextPath }/changeNotice/saveChangeNotice.do',
			data : $('#addform').serialize(),
			type : "post",
			dataType : "json",
			}).done(
				function(res) {
					if (res > 0) {
						toastr.success('新增成功！');
						setTimeout(function(){  //使用  setTimeout（）方法设定定时2000毫秒
							//关闭模态框
							// 父页面刷新
							window.location.reload();  
						},2000);
					}
				}
			).fail(
				function(res) {
					layer.close(1);
					toastr.error('新增失败！');
				}
			)
			return false;
    });
});

toastr.options.positionClass = 'toast-top-center'; //提示框的位置设置为中上
//处理记录
function attachDeviceEvent(reserve5,reserve2,qSignature,reserve3,tSignature,reserve4,maSignature,mOpinion,mSignature){
    layer.open({
        type: 1 					//Page层类型
        ,area: ['600px', '350px']   //宽  高
        ,title: '处理记录'
        ,shade: 0.6 				//遮罩透明度
        ,maxmin: true 			    //允许全屏最小化
        ,anim: 1 					//0-6的动画形式，-1不开启
        ,content: '<div id="lookupTable1"></div>'
        ,success: function(){
			if (reserve5 == '1') {
				$('#lookupTable1').append('<div style="margin: 5em 0 0 0;text-align: center;font-size: 20px;">未处理</div>')
			}
			if (reserve5 == '2') {
				$('#lookupTable1').append('<div class="layui-form" style="margin: 1em;"><table class="layui-table"><colgroup>'+
						'<col width="150"><col width="150"><col width="200"><col></colgroup><thead><tr>'+
						'<th>操作部门</th><th>操作人</th><th>意见</th></tr></thead><tbody><tr><td>品质监控部</td>'+
						'<td>'+qSignature+'</td><td>'+reserve2+'</td></tr></tbody></table></div>')
			}
			if (reserve5 == '3') {
				$('#lookupTable1').append('<div class="layui-form" style="margin: 1em;"><table class="layui-table"><colgroup>'+
						'<col width="150"><col width="150"><col width="200"><col></colgroup><thead><tr>'+
						'<th>操作部门</th><th>操作人</th><th>意见</th></tr></thead><tbody><tr><td>品质监控部</td>'+
						'<td>'+qSignature+'</td><td>'+reserve2+'</td></tr><tr><td>生产技术部</td><td>'+tSignature+
						'</td><td>'+reserve3+'</td></tr></tbody></table></div>')
			}
			if (reserve5 == '4') {
				$('#lookupTable1').append('<div class="layui-form" style="margin: 1em;"><table class="layui-table"><colgroup>'+
						'<col width="150"><col width="150"><col width="200"><col></colgroup><thead><tr>'+
						'<th>操作部门</th><th>操作人</th><th>意见</th></tr></thead><tbody><tr><td>品质监控部</td>'+
						'<td>'+qSignature+'</td><td>'+reserve2+'</td></tr><tr><td>生产技术部</td><td>'+tSignature+
						'</td><td>'+reserve3+'</td></tr><tr><td>生产制造部</td><td>'+maSignature+'</td><td>'+
						reserve3+'</td></tr></tbody></table></div>')
			}
			if (reserve5 == '5') {
				$('#lookupTable1').append('<div class="layui-form" style="margin: 1em;"><table class="layui-table"><colgroup>'+
						'<col width="150"><col width="150"><col width="200"><col></colgroup><thead><tr>'+
						'<th>操作部门</th><th>操作人</th><th>意见</th></tr></thead><tbody><tr><td>品质监控部</td>'+
						'<td>'+qSignature+'</td><td>'+reserve2+'</td></tr><tr><td>生产技术部</td><td>'+tSignature+
						'</td><td>'+reserve3+'</td></tr><tr><td>生产制造部</td><td>'+maSignature+'</td><td>'+
						reserve3+'</td></tr><tr><td>基地经理</td><td>'+mSignature+'</td><td>'+mOpinion+'</td></tr></tbody></table></div>')
			}
        }
    });
}
</script>

</body>
</html>